package com.huyna88.touchsetting;

import com.huyna88.touchsetting.view.RecView;

import android.app.Service;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class TouchService extends Service{
//	Button btnTouch;
	ImageView imgTouch;
	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		imgTouch = new ImageView(this);
		imgTouch.setBackgroundResource(R.drawable.mouse);
		imgTouch.setOnClickListener(new onClickImage());
		//
		WindowManager.LayoutParams params = new WindowManager.LayoutParams(
				WindowManager.LayoutParams.WRAP_CONTENT,
				WindowManager.LayoutParams.WRAP_CONTENT,
				WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
				WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
				PixelFormat.TRANSLUCENT);
		params.gravity = Gravity.RIGHT|Gravity.CENTER;
		WindowManager wm = (WindowManager)getSystemService(WINDOW_SERVICE);
		wm.addView(imgTouch, params);
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		if(imgTouch!=null){
			((WindowManager)getSystemService(WINDOW_SERVICE)).removeView(imgTouch);
			imgTouch = null;
		}
	}
	
	private class onClickImage implements OnClickListener{

		@Override
		public void onClick(View v) {
			Toast.makeText(getApplicationContext(), "Hello...!", Toast.LENGTH_SHORT).show();
		}
		
	}
}
